#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<string.h>
struct Stu
{
	char name[20];
	int age;
};

int cmp(const void* p, const void* q)
{
	return strcmp(((struct Stu*)p)->name, ((struct Stu*)q)->name);
}


void swap(char*p,char*q,size_t width)
{
	int i = 0;
	for (i = 0; i < width; i++)
	{
		char tmp = *p;
		*p = *q;
		*q = tmp;
		p++;
		q++;
	}
}

void print(struct Stu*p,size_t sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%s %d\n", (p + i)->name, (p + i)->age);
	}
}

void My_qsort(int* base, size_t len, size_t width, int (*cmp)(const void* p, const void* q))
{
	int i = 0;
	for (i = 0; i < len; i++)
	{
		int j = 0;
		for (j = 0; j < len-i-1; j++)
		{
			if (cmp((char*)base+j*width,(char*)base+(j+1) * width)>0)
			{
				swap((char*)base + j*width, (char*)base + (j + 1)*width,width);
			}
		}
	}
}

void test()
{
	struct Stu arr[] = { {"zhangsan",29}, {"lisi",18},{"wangwu",20} };
	My_qsort(arr, sizeof(arr) / sizeof(arr[0]), sizeof(arr[0]), cmp);
	print(arr,sizeof(arr)/sizeof(arr[0]));
}

int main()
{
	test();
	return 0;
}